import pandas as pd
import numpy as np
import os
from typing import List

hmd=[
'300431',
'600781',
'000408',
'002638',
'002219',
'600139',
'000835',
'002071',
'002512',
'300269',
'300426',
'600319',
'600800',
'603030',
'000839',
'002076',
'600069',
'300116',
'600671',
'002770',
'300168',
'600086',
'603555',
'300187',
'300362',
'000567',
'000557',
'603157',
'300090',
'300029',
'000020',
'000038',
'601579',
'300108',
'600856',
'603188',
'002098',
'300411',
'002694',
'600255',
'600532',
'600358',
'600212',
'002006',
'300325',
'002354',
'000410',
'000861',
'300104',
'600393',
'000426',
'300093',
'601258',
'601113',
'002477',
'000835',
'002071',
'600677',
'002547',
'600319',
'603779',
'300312',
'002173',
'002069',
'000413',
'000040',
'600290',
'300176',
'600758',
'000038',
'603555',
'000681',
'600712',
'002464',
'600237',
'600393',
'002517',
'000620',
'002370',
'601101',
'601918',
'300307',
'000039',
'000727',
'000423',
'600198',
'002256',
'000980',
'002739',
'600986',
'600816',
'002176',
'600239',
'002662',
'002466',
'002537',
'000697',
'002491',
'300459',
'600416',
'000509',
'600306',
'600122',
'600333',
'600530',
'000536',
'002496',
'002192',
'600243',
'002513',
'002121',
'000837',
'600175',
'002447',
'000669',
'000890',
'002319',
'002247',
'002681',
'002529',
'600311',
'002509',
'000595',
'603389',
'002255',
'000687',
'002765',
'000673',
'600821',
'000017',
'002280',
'002426',
'000587',
'600734',
'000679',
'600892',
'002077',
'002418',
'600898',
'002502',
'600568',
'600555',
'002052',
'002535',
'000663',
'000780',
'600651',
'600280',
'600470',
'000927',
'300064',
'002239',
'300273',
'300598',
    ]
exclude=[]
for codeStr in hmd:
    if ((codeStr<'009999')|((codeStr>='300000') & (codeStr<='309999'))):
        codeStr+='.SZ'
    elif ((codeStr>='600000') & (codeStr<='609999')):
        codeStr+='.SH'
    else:
        continue
    exclude.append(codeStr)


data=pd.read_excel('综合信息查询_组合证券314_20200421.xls')
position=list(data['持仓'])
buypos=list(data['当日买量'])
stocks=list(data['证券代码'])
names=list(data['证券名称'])
mv=list(data['市值'])
price=list(data['最新价'])
account=list(data['组合编号'])
codeList=[]
for i in range(len(stocks)):
    if np.isnan(stocks[i]):
        continue
        
    code=int(stocks[i])
    pos=position[i]
    #pos=position[i]-buypos[i]
    #pos=np.floor(pos*1/100)*100
    codeStr=str(code).rjust(6,'0')
    acc=int(account[i])
    if ((codeStr<'009999')|((codeStr>='300000') & (codeStr<='309999'))):
        codeStr+='.SZ'
    elif ((codeStr>='600000') & (codeStr<='609999')):
        codeStr+='.SH'
    else:
        continue
    codeList.append({'code':codeStr,'account':acc,'hold':pos,'name':names[i],'marketValue':mv[i],'price':price[i]})
allStocks=pd.DataFrame(codeList)




myStocks=allStocks[allStocks['account']==300140013]

print(300140013)

#deleteCodes=["002223.SZ","601238.SH"]
#myStocks=myStocks[~myStocks['code'].isin(deleteCodes)]
if myStocks.shape[0]>0:
    stocks=myStocks.set_index(['code'])
    stocks['parameter1']=0.004
    stocks['parameter2']=0.4
    mv=(stocks['hold']*stocks['price']).sum()
    mv=stocks['marketValue'].sum()
    print(mv)
    stocks=stocks.reset_index();
    stocks['hold']=np.floor(stocks['hold']/100.0)*100
    #stocks=stocks[stocks['hold']>=200]
    #stocks=stocks[stocks['price']>=5]
    mv=(stocks['hold']*stocks['price']).sum()
    print(mv)
    stocks=stocks[['code','hold','parameter1','parameter2']]
    stocks.to_csv("stockT0220200422.csv",index=0,header=0)
    control=stocks[['code','hold']]
    control.to_csv("controlT0220200422.csv",index=0,header=0)
print("+++++++++++++++++++++++++++++++++++++++++")








